﻿<?php
	include 'config.php';
	//$query = "SELECT c.id, c.codigo AS codigo, c.descripcion, r.codigo AS rango, r.detalles FROM cie c, rangos_cie r WHERE c.id = " . $id . " AND c.id_rango_cie_fk = r.id";
	$query = "SELECT c.id, c.codigo AS codigo, c.descripcion, r.rango, r.detalles FROM cie c, rangos_cie r WHERE c.id = :id AND c.id_rango_cie_fk = r.id";
	$valores = array(':id' => $_GET["id"]);
	try {
		$dbh = new PDO('mysql:host=' . $host . ';dbname=' . $db, $user, $password, $options);
		$codigos = array();
		$json = "";
		$result = $dbh->query($query);
		
		
		$stmt = $dbh -> prepare($query);
		$stmt -> execute($valores);
		//echo "\nPDOStatement::errorInfo():\n";
		//$arr = $stmt->errorInfo();
		//print_r($arr);
		$numFilas = $stmt -> rowCount();
		if ($numFilas == 1){
			$row = $stmt -> fetch();
			$json .= '{"id": "' . $row['id'] . '", "codigo": "' . $row['codigo'] . '", "descripcion": "' . htmlspecialchars($row['descripcion']) . '", "rango": "' . $row['rango'] . '", "detalles": "' . htmlspecialchars($row['detalles']) . '"}';
			//echo print_r($row);
		}
		
		
		/* if($result !== false) {
			$row = $result -> fetch();
			$json .= '{"id": "' . $row['id'] . '", "codigo": "' . $row['codigo'] . '", "descripcion": "' . htmlspecialchars($row['descripcion']) . '", "rango": "' . $row['rango'] . '", "detalles": "' . htmlspecialchars($row['detalles']) . '"}';
			$result -> fetch();
		} */
		//echo print_r($row);
		echo $json;
		$dbh = null;
	} catch (PDOException $e) {
		print "Error!: " . $e->getMessage() . "<br/>";
		die();
	}
?>